addpath('/Users/marcelomattar/Dropbox/Marcelo/UPenn/Documents/Projects/ITIanalysis/Scripts/Analyses/ROI_Analysis');

subjectList = {...
    'D121412K'...
    'M121412M'...
    };


subjectsDir = '/Users/marcelomattar/Data/ITIanalysis/Subjects/';
numSubjects = length(subjectList);


for subjIndx = 1:numSubjects
    [averageBetas , ~, averageBetasMatrix stdBetasMatrix] = extractROImask(subjectList{subjIndx}, subjectsDir);
    
    ITIs = zeros(size(averageBetasMatrix,1),1);
    fullModel = zeros(size(averageBetasMatrix,1),1);
    tempDeriv = zeros(size(averageBetasMatrix,1),1);
    for i=1:size(averageBetasMatrix,1)
        ITIs(i) = str2double(averageBetas{i+1,1});
        fullModel(i) = strcmp(averageBetas{i+1,2},'1-6');
        tempDeriv(i) = averageBetas{i+1,3};
    end
    
    figure(1);
    subplot(1,numSubjects,subjIndx)
    scatter(ITIs(logical(tempDeriv),1), averageBetasMatrix(logical(tempDeriv),3), 50, fullModel(logical(tempDeriv),1), 'filled');
    hold on;
    scatter(ITIs(~logical(tempDeriv),1), averageBetasMatrix(~logical(tempDeriv),3), 50, fullModel(~logical(tempDeriv),1), '+');
    title(subjectList{subjIndx});
    xlabel('Inter-trial interval');
    ylabel('Average Beta value');
    
    figure(2);
    subplot(4,numSubjects,subjIndx);
    bar(ITIs(and(~fullModel,~logical(tempDeriv))),averageBetasMatrix(and(~fullModel,~logical(tempDeriv)),3))
    hold on;
    errorbar(ITIs(and(~fullModel,~logical(tempDeriv))),averageBetasMatrix(and(~fullModel,~logical(tempDeriv)),3),stdBetasMatrix(and(~fullModel,~logical(tempDeriv)),3),'.');
    axis([500 2500 0 110]);
    title(subjectList{subjIndx});
    if subjIndx==1; ylabel('1 back, ~TempDer'); end;
    
    subplot(4,numSubjects,subjIndx+numSubjects);
    bar(ITIs(and(~fullModel,logical(tempDeriv))),averageBetasMatrix(and(~fullModel,logical(tempDeriv)),3))
    hold on;
    errorbar(ITIs(and(~fullModel,logical(tempDeriv))),averageBetasMatrix(and(~fullModel,logical(tempDeriv)),3),stdBetasMatrix(and(~fullModel,logical(tempDeriv)),3),'.');
    axis([500 2500 0 110]);
    if subjIndx==1; ylabel('1 back, TempDer'); end;
    
    subplot(4,numSubjects,subjIndx+2*numSubjects);
    bar(ITIs(and(fullModel,~logical(tempDeriv))),averageBetasMatrix(and(fullModel,~logical(tempDeriv)),3))
    hold on;
    errorbar(ITIs(and(fullModel,~logical(tempDeriv))),averageBetasMatrix(and(fullModel,~logical(tempDeriv)),3),stdBetasMatrix(and(fullModel,~logical(tempDeriv)),3),'.');
    axis([500 2500 0 110]);
    if subjIndx==1; ylabel('1-6 back, ~TempDer'); end;
    
    subplot(4,numSubjects,subjIndx+3*numSubjects);
    bar(ITIs(and(fullModel,logical(tempDeriv))),averageBetasMatrix(and(fullModel,logical(tempDeriv)),3))
    hold on;
    errorbar(ITIs(and(fullModel,logical(tempDeriv))),averageBetasMatrix(and(fullModel,logical(tempDeriv)),3),stdBetasMatrix(and(fullModel,logical(tempDeriv)),3),'.');
    axis([500 2500 0 110]);
    xlabel('ITI');
    if subjIndx==1; ylabel('1-6 back, TempDer'); end;
    
end